//
//  JSNetManager.h
//  Zhaijia(SJD)
//
//  Created by mac on 17/3/14.
//  Copyright © 2017年 刘超. All rights reserved.
//

#import <Foundation/Foundation.h>




/*! 定义上传进度 block */
typedef void( ^ JSUploadProgress)(int64_t bytesProgress,
int64_t totalBytesProgress);
/*! 定义下载进度 block */
typedef void( ^ JSDownloadProgress)(int64_t bytesProgress,
int64_t totalBytesProgress);
/*！定义请求类型的枚举 */
typedef NS_ENUM(NSUInteger, JSHttpRequestType)
{
    /*! get请求 */
    JSHttpRequestTypeGet = 0,
    /*! post请求 */
    JSHttpRequestTypePost,
    /*! put请求 */
    JSHttpRequestTypePut,
    /*! delete请求 */
    JSHttpRequestTypeDelete
};
/*! 定义请求成功的 block */
typedef void( ^ JSResponseSuccess)(id response);
/*! 定义请求失败的 block */
typedef void( ^ JSResponseFail)(NSError *error);
/*!
 *  方便管理请求任务。执行取消，暂停，继续等任务.
 *  - (void)cancel，取消任务
 *  - (void)suspend，暂停任务
 *  - (void)resume，继续任务
 */
typedef NSURLSessionTask JSURLSessionTask;
@interface JSNetManager : NSObject


+ (JSNetManager *)sharedJSNetManager;

+ (JSURLSessionTask *)js_requestWithType:(JSHttpRequestType)type
                               urlString:(NSString *)urlString
                              parameters:(NSMutableDictionary *)parameters
                            successBlock:(JSResponseSuccess)successBlock
                            failureBlock:(JSResponseFail)failureBlock;
/*!
 *  上传图片(多图)
 *
 *  @param parameters   上传图片预留参数---视具体情况而定 可移除
 *  @param imageArray   上传的图片数组
 *  @param fileName     上传的图片数组fileName
 *  @param urlString    上传的url
 *  @param successBlock 上传成功的回调
 *  @param failureBlock 上传失败的回调
 *  @param progress     上传进度
 */
+ (JSURLSessionTask *)js_uploadImageWithUrlString:(NSString *)urlString
                                       parameters:(NSDictionary *)parameters
                                       imageArray:(NSArray *)imageArray
                                         fileName:(NSString *)fileName
                                     successBlock:(JSResponseSuccess)successBlock
                                      failurBlock:(JSResponseFail)failureBlock
                                   upLoadProgress:(JSUploadProgress)progress;
/**
 *  当前项目数据请求封装
 *  @methond        方法名
 *  @isShowLoad     是否显示加载视图
 *  @isShowFinish   是否显示加载完成视图
 *  @parameters     参数
 *  @successBlock   请求成功回调
 *  @failureBlock   请求失败回调
 *  @isCache        缓存机制 待定
 */
+(void)js_courrentProjectRequestWithMouth:(NSString *) methond
                                    cache:(BOOL)isCache
                        ifShowFinishStatu:(BOOL)isShowFinish
                               parameters:(NSMutableDictionary *)parameters
                             successBlock:(JSResponseSuccess)successBlock
                             failureBlock:(JSResponseFail)failureBlock;
/*!
 *  上传图片(多图)
 *
 *  @param parameters   上传图片预留参数---视具体情况而定 可移除
 *  @param imageArray   上传的图片数组
 *  @param fileName     上传的图片数组fileName
 *  @param urlString    上传的url
 *  @param successBlock 上传成功的回调
 *  @param failureBlock 上传失败的回调
 *  @param progress     上传进度
 */
+ (JSURLSessionTask *)js_currentUploadImageWithUrlString:(NSString *)urlString
                                         showLoadingView:(UIView *)inView
                                       parameters:(NSDictionary *)parameters
                                       imageArray:(NSArray *)imageArray
                                         fileName:(NSString *)fileName
                                     successBlock:(JSResponseSuccess)successBlock
                                      failurBlock:(JSResponseFail)failureBlock
                                   upLoadProgress:(JSUploadProgress)progress;
+ (JSURLSessionTask *)js_currentUploadImageWithUrlString:(NSString *)urlString
                                         showLoadingView:(UIView *)inView
                                                  method:(NSString *)method
                                              parameters:(NSDictionary *)parameters
                                              imageArray:(NSArray *)imageArray
                                                fileName:(NSString *)fileName
                                            successBlock:(JSResponseSuccess)successBlock
                                             failurBlock:(JSResponseFail)failureBlock
                                          upLoadProgress:(JSUploadProgress)progress;
/*!
 *  图片上传
 */
//UPLOADPOST数据请求
//+(void)UPLOADPOST:(NSString *)methond imgArray:(NSArray *)imgArray success:(void (^)(id))success failure:(void (^)(NSError *))failure;

#pragma mark - 取消 Http 请求
/*!
 *  取消所有 Http 请求
 */
+ (void)js_cancelAllRequest;

/*!
 *  取消指定 URL 的 Http 请求
 */
+ (void)js_cancelRequestWithURL:(NSString *)URL;
@end
@interface JSNetManager (tools)

+ (NSString *)getTime;
//唯一标识
+ (NSString *)getDeviceIdentifier;

//MD5加密
+ (NSString *)getPsdMD5String:(NSString *)psd;

//字典转Json字符串
+ (NSString*)dictionaryToJson:(NSDictionary *)dic;
//Json字符串转字典
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
+ (NSArray *)arrayWithJsonString:(NSString *)jsonString;
+ (NSString *)jsonStringWithArray:(NSArray *)array;
/* 加密 */
+ (NSString *) AES128Encrypt:(NSDictionary *)dic;
/* 解密 */
+ (NSDictionary *) AES128Decrypt:(NSString *)encryptText;

@end
